//var server_url='http://localhost:8080/LianniuWeb/';
//var server_url='http://47.95.11.244:8082/LianniuWeb/';
var server_url='http://www.nashannacha.com/LianniuWeb/'
var appId = 'wxb0f5fe89c5840bf4';
var specId = localStorage.getItem("specId");
var catchId = localStorage.getItem("catchId");
var weightId = localStorage.getItem("weightId");
var productId = localStorage.getItem("productName");
var PicturePath1 = localStorage.getItem("PicturePath1");
var PicturePath2 = localStorage.getItem("PicturePath2");
var PicturePath3 = localStorage.getItem("PicturePath3");
var price = localStorage.getItem("price");
var overPlusNum = localStorage.getItem("overPlusNum");
var remark = localStorage.getItem("remark"); 
var userid = null;
var hrefUrl = window.location.href;
if(hrefUrl.indexOf("buyer") != -1) {
	userid = localStorage.getItem("buyer_userid");
}else if( hrefUrl.indexOf("staff") != -1) {
	userid = localStorage.getItem("staffId");
} else{
	userid = localStorage.getItem("seller_userid");
}
console.log(userid)
var username = localStorage.getItem("username");
var token = localStorage.getItem("token");
var pasteData;

function isPhone(userNumb){//验证手机号码
	var reg = /^[1][34578][0-9]{9}$/;
	return reg.test(userNumb);
};
var contants ={
	"notIsPhone":"输入的手机号不正确",
	"notEquals":"密码输入不一致",
	"systemError":"系统异常",
	"buyerNoAddr":"您还没填写收货地址,请填写收货地址.",
	"skuNumExc":"选购数量大于库存",
	'loadingMsg':'<li id="loading"><img src="/LianniuWeb/img/loading.gif"; id="loadingImg"/><p>正在加载</p></li>'
};
function equals(value1,value2){
	return value1==value2;
}
function checkStrLength(userPass,min,max){//验证密码
	if(userPass.length<min || userPass.length >max){	
	    easyAlert("输入字符长度须在"+min+"-"+max+"之间!");
	    return false;
	}else{
		return true;
	};
};
function chinese(china){  //验证只能是中文
	var pattern = /^[\u4e00-\u9fa5]*$/;
	if(!pattern.test(china)){
		easyAlert("名称不能为空且必须为中文");
		return false;
	}else{
		return true;
	}
};
function isDouble(num){
	var reg = /^\d+(?:\.\d{2})?$/;
	return reg.test(num);
};
function isPriceNumber(_keyword){  
    if(_keyword == "0" || _keyword == "0." || _keyword == "0.0" || _keyword == "0.00"){  
        _keyword = "0"; return true;  
    }else{  
        var index = _keyword.indexOf("0");  
        var length = _keyword.length;  
        if(index == 0 && length>1){/*0开头的数字串*/  
            var reg = /^[0]{1}[.]{1}[0-9]{1,2}$/;  
            if(!reg.test(_keyword)){  
                return false;  
            }else{  
                return true;  
            }  
        }else{/*非0开头的数字*/  
            var reg = /^[1-9]{1}[0-9]{0,10}[.]{0,1}[0-9]{0,2}$/;  
            if(!reg.test(_keyword)){  
                return false;  
            }else{  
                return true;  
            }  
        }             
        return false;  
    }  
};
//检验正则
function isChinese(temp) { 
 var re = /[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\:\.\-\_\,\、\。\%\%\()\{}\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/; 
 if(re.test(temp)) return false; 
 return true; 
};
function isInt(temp) {
	var re = /\d{0,}/;
	if(!re.test(temp)) return false;
	return true;
};
var goBack = function(){
	window.history.go(-1);
	localStorage.setItem("goBack","goBack");
}
var reLoad = function(){
	if(null != localStorage.getItem("goBack")){
		localStorage.removeItem("goBack");
		window.location.reload();
	}
}
var orginalAlert = window.alert;
function alertLogin(){
	//orginalAlert("请先登录")
	window.location.href='/LianniuWeb/login.do';
}
function alertSupplyLogin(){
	//orginalAlert("请先登录")
	window.location.href='/LianniuWeb/login.do?supply=1';
}

window.alert=function(msg){
	easyAlert(msg);
	return;
}
var appendNullKey = function(){
	var s = '<div style="height:5rem;" id="nullKey"></div>'
		if($('#nullKey').length<1){
			$(document.body).append(s);
		}
}
var removeNullKey = function(){
	if($('#nullKey').length>0){
		$('#nullKey').remove();
	}
}
var toBuyer = function(){
	window.location.href=server_url+"buyer/product/index.do";
}
var toSupply = function(){
	window.location.href=server_url+"index.do";
}
//确认框工具
var confirmUtil=function(title,fn){
	confirmInit(title);
	function confirmInit(title){
		var msg ='<div id="confirmParent" style="position:absolute;left:0; top:0; display: block; width:100%; height:100%;">'+
			'<div id="confirmUtil" style="background-color: #000; opacity:.6; width:100%; height:100%; ">'+
			'</div>'+
			'<div id="maskConfirmUtil" style="position:absolute; left:50%; top:50%; background: #fff; width:5.5rem; height:2rem; border-radius:0.1rem; margin:-2rem -2.75rem 0;">'+
			'<h3 style="background:#0db664; color:#fff;font-weight:normal; font-size:0.35rem; text-align: center;line-height: 1rem; border-radius:0.1rem 0.1rem 0 0 ">'+title+'</h3>'+
			'<button id="conSure" style="width:2.75rem; height:1rem; border-radius:0 0 0 0.1rem;float:left; border-right:1px solid #ccc; background: #fff; font-size:0.35rem; color:#0db664"">确定</button>'+
			'<button id="conCancel" style="width:2.75rem; height:1rem; border-radius:0 0 0.1rem 0; background: #fff; font-size:0.35rem; color:#0db664">取消</button>'+
			'</div>'+
			'</div>';
		$(document.body).append(msg);
	}
	$('#conSure').click(function(){
		destrioy();
		fn(true);
	});
		
	$('#conCancel').click(function(){
		destrioy();
		fn(false);
	});
	function destrioy(){
		$('#confirmParent').remove();
	}
}
function detailGoBack(){
	window.location.href=server_url+"buyer/product/index.do";
}
function orderStatusName(){
	var orderStatus = [];
	orderStatus.push("01","初始化");
	orderStatus.push("02","正在找货");
	orderStatus.push("03","找货完成");
	orderStatus.push("04","已交款");
	orderStatus.push("05","已发货");
	orderStatus.push("06","已签收");
	orderStatus.push("07","已评价");
	orderStatus.push("08","已取消");
	return orderStatus;
}

function easyAlert(content){
	var html = "<div id='general_popup' style='position: fixed;left: 0;top: 0;height: 100%;width: 100%;\
    background-color: rgba(255, 255, 255, 0);display: flex;\
    justify-content: center;align-items: center;z-index: 999999999;'>\
    <div style='position: relative;\
    width: 68%;\
    background: rgba(0, 0, 0, 0.5);\
    border-radius: 4px;'><p style='padding: 10px 4%;\
	font-size: 0.4rem;\
	color: #fff;\
	text-align: center;'>"+ content +"</p></div></div>";
	$('body').append(html);

	setTimeout(function(){
		$("#general_popup").remove()
	},1500)
}
/**
 * 双击事件 会回传触发事件的元素
 * @param id 事件触发的element id
 * @param dbFunc  双击触发的函数
 * @param singleFun 单击触发的函数
 */
function doubleClick(id,dbFunc,singleFun){
	//$("#"+id).dblclick(function(){
	//	dbFunc($("#" + id));
	//})
	$("#"+id).click(function (e) {
		dbFunc($("#"+id));
		//var $this = $(this);
		//if ($this.hasClass('clicked')){
		//	$this.removeClass('clicked');
		//	if(dbFunc){
		//		dbFunc($("#"+id));
		//	}
		//	//here is your code for double click
		//}else{
		//	$this.addClass('clicked');
		//	setTimeout(function() {
		//		if ($this.hasClass('clicked')){
		//			$this.removeClass('clicked');
		//			if(singleFun){
		//				singleFun($("#"+id));
		//			}
		//			//your code for single click
		//		}
		//	}, 1500);
		//}
	});
}

//tea项目跳转到详情页面的公用函数，三个参数 ，要跳转的类型，跳转要带的参数，要展示的id
function jumpDetail(type,param,productId){
	param.productId = productId;
	param.type = type;
	localStorage.setItem('param',JSON.stringify(param));
	if(type=='1'){//茶旅联盟
		window.location = server_url + "teaClub.do";
	}else if(type=='2'){//茶人茶艺
		window.location = server_url + "skillDetail.do";
	}else if(type=='3'){//茶产品
		window.location = server_url + "proDetail.do";
	}else if(type=='4'){//茶区农产
		//window.location = server_url + ".do";
	}else if(type=='5'){//茶山估价
		//window.location = server_url + "order.do";
	}else if(type=='6'){//茶山市场
		window.location = server_url + "gardenDetail.do";
	}else if(type=='7'){//资讯
		window.location = server_url + "infDetail.do";
	}
}
//后台服务报错同意提示
function showErrorMsg(data){
	console.log(data);
	alert("服务器错误");
}
//检查输入值是否为空
function checkNull(str, msg) {
	if (str) {
		if (str === '') {
			alert(msg);
			return false;
		}else{
			return true;
		}
	} else {
		alert(msg);
		return false;
	}
}
function checkNullCal(str) {
	if (str) {
		if (str === '') {
			return false;
		}else{
			return true;
		}
	} else {
		return false;
	}
}
//解析图片
function getPics(prodPic){
	var cslmPic = prodPic.cslmPic;
	var syPic = prodPic.syPic;
	var zgcyPic = prodPic.zgcyPic;
	var cycsPic = prodPic.cycsPic;
	var zshjPic = prodPic.zshjPic;
	var jtPic = prodPic.jtPic;
	var hdnrPic = prodPic.hdnrPic;
	var cshjPic = prodPic.cshjPic;
	
	var imgStr = '';
	
	if(cslmPic){
		imgStr += cslmPic+",";
	}
	if(syPic){
		imgStr += syPic+",";
	}
	if(zgcyPic){
		imgStr += zgcyPic+",";
	}
	if(cycsPic){
		imgStr += cycsPic+",";
	}
    if(zshjPic){
		imgStr += zshjPic+",";
	}
    if(jtPic){
		imgStr += jtPic+",";
	}
    if(hdnrPic){
		imgStr += hdnrPic+",";
	}
    if(cshjPic){
		imgStr += cshjPic+",";
	}
	imgStr = imgStr.substring(0,imgStr.length-1)
	
	
	return imgStr.split(",");
}
function jumpToIndex(msg,time){
	alert(msg);
	setTimeout(toIndex,time);
}
//跳转到首页
function toIndex(){
	window.location=server_url+"buyer/product/index.do";
}